package com.cx.base.day24_RabbitMQ;

import com.rabbitmq.client.*;

/**
 * @Author: songyahui
 * @Date: 2020/8/24 20:04
 * @Version 1.0
 */

public class Send_Exchange {
    private final static String EXCHANGE_NAME = "fanout_exchange_test";
    private final static String QUEUE_NAME = "simple_queue22";

    public static void main(String[] args) {

        try {
//            获取到连接
            Connection con = ConnectionUtil.getConnection();
//            创建通道
            Channel channel = con.createChannel();
//            声明队列
            channel.exchangeDeclare(EXCHANGE_NAME, "fanout");
//            消息内容
            String message = "hello world!";
//            向指定队列发送消息
            channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes());
            System.out.println("[procedure] sent '" + message + "'");
            channel.close();
            con.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

